#ifndef _OP_POOL_H_
#define _OP_POOL_H_

#include "speed_def.h"

// 异步操作池结构
#define ASYNC_POOL_SIZE 1024

struct async_op_pool {
	struct async_op *ops[ASYNC_POOL_SIZE]; // 所有操作指针数组
	struct list_head free_list; // 空闲链表
	int free_count;
	int total_count; /* == ASYNC_POOL_SIZE */
	spinlock_t lock; // 保护池的锁
	wait_queue_head_t wait_queue; // 等待可用操作的队列
	atomic64_t executed_ops; // 已执行操作数
};

struct async_op {
	struct async_op_pool *pool; // 所属池指针
	bool in_use;
	bool is_hash;
	u64 throughput; /* MB/s */
	struct list_head list; // 链表节点
	struct scatterlist sg_src;
	struct scatterlist sg_dst;
	u8 *src_buf;
	u8 *dst_buf;
	struct crypto_wait wait;
	union {
		struct skcipher_request *skreq;
		struct ahash_request *ahreq;
	};
};

int init_async_op_pool(struct thread_data *tdata);

struct async_op *get_async_op(struct thread_data *tdata, int timeout_ms);

int get_async_ops_batch(struct thread_data *tdata, struct async_op **ops, int count,
			int timeout_ms);

void put_async_op(struct thread_data *tdata, struct async_op *op);

void put_async_op2pool(struct async_op_pool *pool, struct async_op *op);

void put_async_ops_batch(struct thread_data *tdata, struct async_op **ops, int count);

void cleanup_async_op_pool(struct thread_data *tdata);

void get_pool_status(struct thread_data *tdata, int *free_count, int *total_count);

void async_skcipher_op_complete(void *data, int error);

#endif
